package com.edu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * @Author:zyn
 * @Date:2025/10/31--11:41:04
 */
public class MyDataSource implements BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {
    private String username;

    private String password;

    private String url;

    private String driver;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        System.out.println("2 执行了属性的set方法");
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    @Override
    public String toString() {
        return "MyDataSource{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", url='" + url + '\'' +
                ", driver='" + driver + '\'' +
                '}';
    }

    public MyDataSource() {
        System.out.println("1 执行了myDataSource构造方法");
    }

    public void myInit(){
        System.out.println("6 执行了自定义初始化方法");
    }

    public void myDestroy(){
        System.out.println("10 执行了自定义销毁方法");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("3 执行了各种Aware接口的方法");
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("5 执行了 InitializingBean的初始化方法");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("9 执行了 DisposableBean接口的销毁方法");
    }

    public void work(){
        System.out.println("8 执行自身的业务方法");
    }
}
